package com.umeng.update;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Handler;
import android.os.Message;
import com.umeng.common.Log;
import com.umeng.common.b.g;
import com.umeng.common.net.k;
import com.umeng.common.net.r;
import com.umeng.common.net.s;
import org.json.JSONObject;

public class UmengUpdateAgent
{
  public static final String a = "1.3.0.20120822";
  private static boolean b = 0;
  private static boolean c = 0;
  private static String d = "update";
  private static final String e = "update";
  private static UmengUpdateListener f = null;
  private static final String g = "umeng_last_update_time";
  private static final String h = "umeng_update_internal";
  private static final String[] i = { "http://au.umeng.com/api/check_app_update", "http://au.umeng.co/api/check_app_update" };
  private static UmengUpdateAgent j = null;
  private static UmengDownloadListener k;
  private static k l = new a();
  private static Handler m = new b();

  private static SharedPreferences a(Context paramContext)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append("umeng_analytic_online_setting_");
    localStringBuffer.append(com.umeng.common.b.u(paramContext));
    return paramContext.getSharedPreferences(localStringBuffer.toString(), 0);
  }

  private static void b(int paramInt, UpdateResponse paramUpdateResponse)
  {
    if (f == null)
      return;
    Message localMessage = new Message();
    localMessage.what = paramInt;
    localMessage.obj = paramUpdateResponse;
    m.sendMessage(localMessage);
  }

  public static void destroy()
  {
    j = null;
  }

  private static UmengUpdateAgent h()
  {
    if (j == null)
      j = new UmengUpdateAgent();
    return j;
  }

  public static void setOnDownloadListener(UmengDownloadListener paramUmengDownloadListener)
  {
    k = paramUmengDownloadListener;
  }

  public static void setUpdateAutoPopup(boolean paramBoolean)
  {
    c = paramBoolean;
  }

  public static void setUpdateListener(UmengUpdateListener paramUmengUpdateListener)
  {
    f = paramUmengUpdateListener;
  }

  public static void setUpdateOnlyWifi(boolean paramBoolean)
  {
    b = paramBoolean;
  }

  public static void showUpdateDialog(Context paramContext, UpdateResponse paramUpdateResponse)
  {
    String str = "";
    try
    {
      if (!(com.umeng.common.b.k(paramContext)))
        str = paramContext.getString(com.umeng.common.c.a(paramContext).f("UMGprsCondition")) + "\n";
      StringBuffer localStringBuffer = new StringBuffer();
      localStringBuffer.append(str);
      localStringBuffer.append(paramContext.getString(com.umeng.common.c.a(paramContext).f("UMNewVersion")));
      localStringBuffer.append(paramUpdateResponse.version);
      localStringBuffer.append("\n");
      localStringBuffer.append(paramUpdateResponse.updateLog);
      AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramContext);
      localBuilder.setTitle(paramContext.getString(com.umeng.common.c.a(paramContext).f("UMUpdateTitle"))).setMessage(localStringBuffer.toString()).setPositiveButton(paramContext.getString(com.umeng.common.c.a(paramContext).f("UMUpdateNow")), new c(paramContext, paramUpdateResponse)).setNegativeButton(paramContext.getString(com.umeng.common.c.a(paramContext).f("UMNotNow")), new d());
      localBuilder.create().show();
      return;
    }
    catch (Exception localException)
    {
      Log.b(d, "Fail to create update dialog box.", localException);
    }
  }

  public static void update(Context paramContext)
  {
    try
    {
      if ((b) && (!(com.umeng.common.b.k(paramContext))))
      {
        b(2, null);
        return;
      }
      if (paramContext == null)
      {
        b(1, null);
        Log.b(d, "unexpected null context in update");
        return;
      }
    }
    catch (Exception localException)
    {
      Log.b(d, "Exception occurred in Mobclick.update(). ", localException);
      return;
    }
    UmengUpdateAgent localUmengUpdateAgent = h();
    localUmengUpdateAgent.getClass();
    new Thread(new a(paramContext)).start();
  }

  public static void update(Context paramContext, long paramLong)
  {
    SharedPreferences localSharedPreferences;
    long l1;
    long l2;
    long l3;
    if (paramContext == null)
      Log.a(d, "unexpected null Context");
    do
    {
      return;
      localSharedPreferences = a(paramContext);
      l1 = localSharedPreferences.getLong("umeng_last_update_time", 0L);
      l2 = localSharedPreferences.getLong("umeng_update_internal", paramLong);
      l3 = System.currentTimeMillis();
    }
    while (l3 - l1 <= l2);
    update(paramContext);
    localSharedPreferences.edit().putLong("umeng_last_update_time", l3).commit();
  }

  public static void update(Context paramContext, String paramString)
  {
    com.umeng.common.a.m = paramString;
    update(paramContext);
  }

  void a(Context paramContext, String paramString)
  {
    Log.a("update", "url: " + paramString);
    new com.umeng.common.net.a(paramContext, "update", com.umeng.common.b.v(paramContext), paramString, l).a();
  }

  public class a extends r
    implements Runnable
  {
    Context a;

    public a(Context paramContext)
    {
      this.a = paramContext;
    }

    private JSONObject a(Context paramContext)
    {
      JSONObject localJSONObject = new JSONObject();
      try
      {
        localJSONObject.put("type", "update");
        localJSONObject.put("appkey", com.umeng.common.b.p(paramContext));
        localJSONObject.put("version_code", com.umeng.common.b.d(paramContext));
        localJSONObject.put("package", com.umeng.common.b.u(paramContext));
        localJSONObject.put("sdk_version", "1.3.0.20120822");
        localJSONObject.put("idmd5", g.b(com.umeng.common.b.f(paramContext)));
        localJSONObject.put("channel", com.umeng.common.b.t(paramContext));
        return localJSONObject;
      }
      catch (Exception localException)
      {
        Log.b(UmengUpdateAgent.c(), "exception in updateInternal", localException);
      }
      return null;
    }

    private void b()
    {
      label35: UpdateResponse localUpdateResponse2;
      JSONObject localJSONObject = a(this.a);
      UmengUpdateAgent localUmengUpdateAgent = UmengUpdateAgent.d();
      localUmengUpdateAgent.getClass();
      UmengUpdateAgent.b localb = new UmengUpdateAgent.b(localUmengUpdateAgent, localJSONObject);
      int i = 0;
      UpdateResponse localUpdateResponse1 = null;
      if (i >= UmengUpdateAgent.e().length)
      {
        localUpdateResponse2 = localUpdateResponse1;
        if (localUpdateResponse2 != null)
          break label101;
        UmengUpdateAgent.a(3, null);
      }
      do
      {
        return;
        localb.a(UmengUpdateAgent.e()[i]);
        localUpdateResponse1 = (UpdateResponse)a(localb, UpdateResponse.class);
        if (localUpdateResponse1 != null)
          localUpdateResponse2 = localUpdateResponse1;
        ++i;
        break label35:
        label101: Log.a(UmengUpdateAgent.c(), "response : " + localUpdateResponse2.hasUpdate);
        if (!(localUpdateResponse2.hasUpdate))
          break label168;
        UmengUpdateAgent.a(0, localUpdateResponse2);
      }
      while (!(UmengUpdateAgent.f()));
      ((Activity)this.a).runOnUiThread(new e(this, localUpdateResponse2));
      return;
      label168: UmengUpdateAgent.a(1, null);
    }

    public boolean a()
    {
      return false;
    }

    public void run()
    {
      try
      {
        b();
        return;
      }
      catch (Exception localException)
      {
        UmengUpdateAgent.a(1, null);
        Log.a(UmengUpdateAgent.c(), "reques update error", localException);
      }
    }
  }

  public class b extends s
  {
    private JSONObject e;

    public b(JSONObject paramJSONObject)
    {
      super(null);
      this.e = paramJSONObject;
    }

    public JSONObject a()
    {
      return this.e;
    }

    public String b()
    {
      return this.c;
    }
  }
}

/* Location:           H:\360云盘\lewa_explorer_3.0\bin\FileApp_orig_dex2jar.jar
 * Qualified Name:     com.umeng.update.UmengUpdateAgent
 * JD-Core Version:    0.5.2
 */